package com.onjava;

import java.util.Random;

/**
 * @author ANG.YU
 * @date 2020-08-06 10:32
 * 随机返回枚举
 */
public class Enums {
    private static Random rand = new Random(47);


    public static <T extends Enum<T>> T random(Class<T> ec) {
        return random(ec.getEnumConstants());
    }

    public static <T> T random(T[] values) {
        return values[rand.nextInt(values.length)];
    }
}
